import { cwbbVK } from './cwbb.js';

function transformCwbbDataXqykjzz(sheet, type, saasData) {
  // console.log(sheet, type, saasData, baseInfoCache);
  let vks;
  vks = cwbbVK.xqykjzz;
  if (sheet === 'balance') {
    let obj = {};
    let VK = vks.balance;
    for (let key in VK) {
      var v = VK[key];
      let saasItem = saasData.data.openParams.inputData.data.balance.find(item => item.reportItemRowNbr === v.replace('h', ''));
      if (key.includes('.qmye')) {
        obj[key] = saasItem.colValue1 || 0
      }
      if (key.includes('.ncye')) {
        obj[key] = saasItem.colValue2 || 0
      }
    }
    return obj;
  }
  if (sheet === 'profit') {
    let obj = {};
    let VK = vks.profit;
    for (let key in VK) {
      var v = VK[key];
      let saasItem = saasData.data.openParams.inputData.data.profit.find(item => item.reportItemRowNbr === v);
      if (key.includes('.bnljje')) {
        obj[key] = saasItem.colValue1 || 0
      }
      if (key.includes('.byje')) {
        obj[key] = saasItem.colValue2 || 0
      }
    }
    return obj;
  }

  if (sheet === 'cash') {
    let obj = {};
    let VK = vks.cash;
    for (let key in VK) {
      var v = VK[key];
      let saasItem = saasData.data.openParams.inputData.data.cash.find(item => item.reportItemRowNbr === v);
      if (key.includes('.bnljje')) {
        // obj[key] = 1
        obj[key] = saasItem.colValue1 || 0

      }
      if (key.includes('.byje')) {
        // obj[key] = 1
        obj[key] = saasItem.colValue2 || 0
      }
    }
    return obj;
  }
}

function transformCwbbDataQykjzz(sheet, type, saasData) {
  let vks = cwbbVK.qykjzz;
  if (sheet === 'balance') {
    let obj = {};
    let VK = vks.balance;
    for (let key in VK) {
      var v = VK[key];

      let saasItem;
      if (v.includes('h')) {
        saasItem = saasData.data.openParams.inputData.data.balance[v.replace('h', '')]
      } else {
        saasItem = saasData.data.openParams.inputData.data.balance.find(item => item.reportItemRowNbr === v)
      }

      if (key.includes('.ncye')) {
        obj[key] = saasItem.colValue2 || 0
      }
      if (key.includes('.qmye')) {
        obj[key] = saasItem.colValue1 || 0
      }
    }
    return obj;
  }

  if (sheet === 'profit') {
    let obj = {};
    let VK = vks.profit;
    for (let key in VK) {
      var v = VK[key];
      let saasItem = saasData.data.openParams.inputData.data.profit.find(item => item.reportItemRowNbr === v);
      if (key.includes('.bqje')) {
        obj[key] = saasItem.colValue1 || 0
      }
      if (key.includes('.sqje1')) {
        obj[key] = saasItem.colValue2 || 0
      }
    }
    return obj;
  }
}




export { transformCwbbDataXqykjzz, transformCwbbDataQykjzz };